package com.fangcun.controller.admin.old;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.fangcun.bean.sys.PageBean;
import com.fangcun.bean.sys.ResponseMsg;
import com.fangcun.common.canstant.ErrCode;
import com.fangcun.common.exception.ProException;
import com.fangcun.common.util.PublicMethod;
import com.fangcun.common.util.apiversion.ApiVersion;
import com.fangcun.entity.MessageData;
import com.fangcun.entity.User;
import com.fangcun.service.admin.MessageDataService;

@RestController
@RequestMapping("/admin/{version}/auth/message")
public class MessageDataController {
	
	private static Logger LOG = LoggerFactory.getLogger(MessageDataController.class);

	@Autowired
	private MessageDataService messageDataService;
	/****/
	@ApiVersion(1.0)
	@RequestMapping(value = "/list" ,method = RequestMethod.POST)
	private ResponseMsg list(@RequestBody PageBean<MessageData> request) {
		ResponseMsg msg=ResponseMsg.returnBeanBuild();
		try {
			msg.setData(messageDataService.list(request));
		} catch (ProException e) {
			LOG.error("-消息列表->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-消息列表->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	/****/
	@ApiVersion(1.0) 
	@RequestMapping(value = "/add",method=RequestMethod.POST)
	private ResponseMsg add(@RequestBody List<MessageData> request) {
		ResponseMsg msg= ResponseMsg.returnBeanBuild();
		try {
			messageDataService.send(request);
		} catch (ProException e) {
			LOG.error("-发布系统信息->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-发布系统信息->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
	/**下拉**/
	@ApiVersion(1.0)
	@RequestMapping(value = "/dropdown",method = RequestMethod.POST)
	private ResponseMsg dropDown(@RequestBody User request) {
		ResponseMsg msg=ResponseMsg.returnBeanBuild();
		try {
			msg.setData(messageDataService.dropDown(request));
		} catch (ProException e) {
			LOG.error("-消息管理 用户下拉->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-消息管理 用户下拉->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
